public class Solution {
    /**
     * 二分查找
     * 
     * @param x
     * @return
     */
    public int mySqrt(int x) {
        int ans=-1;
        int down=0;
        int up =x;
        while(down<=up){
            int mid=down+((up-down)>>1); // 防溢出
            if((long) mid * mid<=x){    //类型转换
                ans=mid;
                down =mid+1;
            }else{
                up=mid-1;
            }
        }
        return ans;
    }
}
